package ru.ifmo.mlarinsky.classificator.map;

import fi.javasom.jsom.InputVectors;
import fi.javasom.jsom.SomNode;
import fi.javasom.jsom.WeightVectors;
import java.util.Arrays;
import java.util.List;
import ru.ifmo.mlarinsky.classificator.math.MathUtil;
import ru.ifmo.mlarinsky.classificator.model.Vector;
import ru.ifmo.mlarinsky.classificator.providers.DeterminationVectorProvider;
import ru.ifmo.mlarinsky.classificator.providers.InstructionsProvider;
import ru.ifmo.mlarinsky.classificator.providers.VectorProvider;

public class SomVectorsBuilder {
    public static InputVectors buildInputVectors(VectorProvider provider) {
        InputVectors mapInputVectors = new InputVectors();
        List<Vector> vectors = provider.getVectors();

        for (Vector vector : vectors)
            mapInputVectors.add(new SomNode(vector.getLabel(), MathUtil.unboxDoubleArray(vector.getValues())));

        return mapInputVectors;
    }

    public static WeightVectors buildWeightVectors(InstructionsProvider provider) {
        return new WeightVectors(provider.getXDimension(),provider.getYDimension(),
                provider.getVectorProvider().getDimensions().length,
                provider.getLatticeType().toString());
    }

    public static void main(String[] args) {
        testBuildVectors();
    }

    private static void testBuildVectors() {
        VectorProvider provider = new DeterminationVectorProvider();
        InputVectors inputVectors = buildInputVectors(provider);

        for (Object object : inputVectors) {
            SomNode node = (SomNode) object;
            System.out.println(node.getLabel() + " -> " + Arrays.toString(node.getValues()));
        }
    }
}
